package com.tjbank.cssys.web.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CreditInstallment;
import com.tjbank.cssys.repository.CreditInstallmentMapper;
import com.tjbank.cssys.web.service.CreditInstallmentService;
import org.apache.ibatis.annotations.Param;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CreditInstallmentServiceImpl implements CreditInstallmentService {

    @Autowired
    private CreditInstallmentMapper creditInstallmentMapper;

    private final static Logger logger = LoggerFactory.getLogger(CreditInstallmentServiceImpl.class);

    @Override
    public CreditInstallment selectByPrimaryKey(Long id) {
        return creditInstallmentMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<CreditInstallment> selectList(CreditInstallment creditInstallment, Integer page, Integer pageSize) {
        logger.info("查询 信用卡个性化分期数据");

        Page<CreditInstallment> objects = PageHelper.startPage(page, pageSize);

        List<CreditInstallment> creditInstallments = creditInstallmentMapper.selectList(creditInstallment);

        PageInfo<CreditInstallment> objectPageInfo = new PageInfo<>(creditInstallments);

        return objectPageInfo;
    }


    @Override
    public int UpdateAudit(CreditInstallment creditInstallment) {

        creditInstallment.setCaseStatue(1);

        return creditInstallmentMapper.UpdateAudit(creditInstallment);
    }

    @Override
    public int deleteByPrimaryKey(@Param("id") Long id) {
        return creditInstallmentMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int UpdatecardStatue(CreditInstallment creditInstallment) {
        logger.info("状态设置为0无效");
        creditInstallment.setCardStatue(0);

        return creditInstallmentMapper.UpdatecardStatue(creditInstallment);
    }

    @Override
    public int insert(CreditInstallment creditInstallment) {
        //卡的状态， 0无效1 有效
        creditInstallment.setCardStatue(1);
        //审批状态。，0未审批 1审批
        creditInstallment.setCaseStatue(0);
        int insert = creditInstallmentMapper.insert(creditInstallment);
        return insert;
    }
}
